/**
 *  @file CircularBuffer.h
 */
#ifndef _CIRCULARBUFFER_H_
#define _CIRCULARBUFFER_H_

#include "BinBuf.h"

namespace cppflib
{

namespace collections
{

/**
 *  A fixed size circular buffer
 */
class _DLLAPI CircularBuffer : public BinBuf
{
private:
    sz_t validStartPos; ///< since it is a circular buffer, buffer can start at arbitrary position

private:
    CircularBuffer(void);

    virtual void Realloc(sz_t reqSize);
    virtual sz_t ReserveSpace(sz_t reqSize);
    virtual u8_t * GetValidEnd() const;
    virtual u8_t * GetRawBuf() const;
    virtual bool MoveData2Front(sz_t startOff);

    u8_t * __GetBufferPtr(sz_t offset) const;
    u8_t * __GetValidEnd() const;
    u8_t * __GetValidStart() const;

public:
    explicit CircularBuffer(sz_t reqSize);
    virtual ~CircularBuffer(void);

    virtual void SetValidLength(sz_t validLen);
    virtual void CopyData(const u8_t * pData, sz_t dataLen, bool isZeroTerm = false);
    virtual void AppendData(const u8_t * pData, sz_t dataLen, bool isZeroTerm = false);
    virtual void ClearBuf();

    sz_t GetData(u8_t * destBuf, sz_t destBufLen, sz_t circularBufOffset);
};

} // end of namespace collections


} // end of namespace cppflib


#endif
